from tortoise import fields

from app.models.base import TimestampMixin, BaseModel

__all__ = [
    'Article',
    'ArticleCateGory',
]


class Article(BaseModel, TimestampMixin):
    """文章实体"""

    id = fields.IntField(pk=True, description='主键')
    cid = fields.IntField(description='分类ID')
    title = fields.CharField(max_length=200, null=True, default='', description='标题')
    intro = fields.CharField(max_length=200, null=True, default='', description='简介')
    summary = fields.CharField(max_length=200, null=False, default='', description='摘要')
    image = fields.CharField(max_length=200, null=False, default='', description='封面')
    content = fields.TextField(null=False, default='', description='内容')
    author = fields.CharField(max_length=32, null=True, default='', description='作者')
    visit = fields.IntField(null=True, default=0, description='浏览')
    sort = fields.SmallIntField(null=False, default=50, description='排序')
    status = fields.SmallIntField(null=False, default=0, description='是否显示: [0=否, 1=是]')

    class Meta:
        table_description = "文章表"
        table = "article"


class ArticleCateGory(BaseModel, TimestampMixin):
    """文章分类实体"""

    id = fields.IntField(pk=True, description='主键')
    name = fields.CharField(max_length=60, null=False, default='', description='名称')
    sort = fields.SmallIntField(null=False, default=50, description='排序')
    status = fields.SmallIntField(null=False, default=0, description='是否显示: [0=否, 1=是]')

    class Meta:
        table_description = "文章分类表"
        table = "article_category"
        fields = ('id', 'name', 'sort', 'status', 'create_time', 'update_time')  # 不包含敏感字段
